package com.example.hanfu.firstpage;


import android.content.Context;

import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hanfu.BitMapUtil;
import com.example.hanfu.R;

import java.util.ArrayList;

import androidx.annotation.NonNull;

public class HanFuAdapter extends ArrayAdapter {
    private static final String TAG = "HanFuAdapter";

    public HanFuAdapter(@NonNull Context context, int resource, @NonNull ArrayList<HanFu> list) {
        super(context, resource, list);
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView=convertView;
        if(itemView==null){
            itemView= LayoutInflater.from(getContext()).inflate(R.layout.list_item,parent,
                    false);
        }
        HanFu item=(HanFu)getItem(position);
        TextView title=(TextView)itemView.findViewById(R.id.item_title);
        TextView href=(TextView)itemView.findViewById(R.id.item_detail);
        TextView content =(TextView)itemView.findViewById(R.id.item_content);
        ImageView img=(ImageView) itemView.findViewById(R.id.image1);
        Log.i(TAG, "adapter:img=" + img);

        //Bitmap bitmap = getLocalBitmap(item.getImg());;
       //Log.i(TAG, "adapter:bitmap=" + bitmap);


        //imageView = (ImageView)this.findViewById(R.id.imageViewId);
        //显示
        Bitmap bitmap= BitMapUtil.returnBitMap(item.getImg());
        img.setImageBitmap(bitmap);
        title.setText(item.getTitle());
        content.setText(item.getContent());
        href.setText(item.getHref());

     return itemView;
    }



    }
